
#include <BSpacer>
#include "member_BSpacer.h"
#include "member_BLayout.h"

using namespace BWE;

#define member					(*(member_BSpacer*)_ptr)
#define member_allocate()		_ptr = new member_BSpacer(this)
#define member_release()		delete (member_BSpacer*)_ptr

BSpacer::BSpacer()
{
	member_allocate();
}
BSpacer::BSpacer(const BSize& size)
{
	member_allocate();
	member.rect.setSize(size);
	member.hintSize = size;
}
BSpacer::BSpacer(const BSize& size, Policy widthPolicy, Policy heightPolicy)
{
	member_allocate();
	member.rect.setSize(size);
	member.hintSize = size;
	member.fixedSize = size;
	this->setSizePolicy(widthPolicy, heightPolicy);
}
BSpacer::BSpacer(int width, int height)
{
	member_allocate();
	member.rect.setSize(width, height);
	member.hintSize.set(width, height);
	member.fixedSize.set(width, height);
}
BSpacer::BSpacer(int width, int height, Policy widthPolicy, Policy heightPolicy)
{
	member_allocate();
	member.rect.setSize(width, height);
	member.hintSize.set(width, height);
	member.fixedSize.set(width, height);
	this->setSizePolicy(widthPolicy, heightPolicy);
}
BSpacer::~BSpacer()
{
	member_release();
}

void BSpacer::setSize(int width, int height)
{
	setSize(BSize(width, height));
}
void BSpacer::setSize(const BSize& size)
{
	BSize temp = size;
	temp.limit(member.minSize, member.maxSize);
	if (member.rect.size() != temp)
	{
		member.rect.setSize(temp);
		this->emit(Signal_Resized, temp);
	}
}
BSize BSpacer::size() const
{
	return member.rect.size();
}

void BSpacer::setRect(int x, int y, int width, int height)
{
	setRect(BRect(x, y, width, height));
}
void BSpacer::setRect(const BRect& rect)
{
	BPoint pos = rect.pos();
	if (member.rect.pos() != pos)
	{
		member.rect.setPos(pos);
		this->emit(Signal_Moved, pos);
	}
	BSize temp = rect.size();
	temp.limit(member.minSize, member.maxSize);
	if (member.rect.size() != temp)
	{
		member.rect.setSize(temp);
		this->emit(Signal_Resized, temp);
	}
}
const BRect& BSpacer::rect() const
{
	return member.rect;
}

void BSpacer::setWidthHint(int widthHint)
{
	setSizeHint(widthHint, member.hintSize.height());
}
int BSpacer::widthHint() const
{
	return member.hintSize.width();
}

void BSpacer::setHeightHint(int heightHint)
{
	setSizeHint(member.hintSize.width(), heightHint);
}
int BSpacer::heightHint() const
{
	return member.hintSize.height();
}

void BSpacer::setSizeHint(int hintWidth, int hintHeight)
{
	setSizeHint(BSize(hintWidth, hintHeight));
}
void BSpacer::setSizeHint(const BSize& hintSize)
{
	if (member.hintSize != hintSize)
	{
		member.hintSize = hintSize;
		if (member.layout)
			member.layout->dirty();
	}
}
const BSize& BSpacer::sizeHint() const
{
	return member.hintSize;
}

void BSpacer::setFixedWidth(int fixedWidth)
{
	setFixedSize(fixedWidth, member.fixedSize.height());
}
int BSpacer::fixedWidth() const
{
	return member.fixedSize.width();
}

void BSpacer::setFixedHeight(int fixedHeight)
{
	setFixedSize(member.fixedSize.width(), fixedHeight);
}
int BSpacer::fixedHeight() const
{
	return member.fixedSize.height();
}

void BSpacer::setFixedSize(int fixedWidth, int fixedHeight)
{
	setFixedSize(BSize(fixedWidth, fixedHeight));
}
void BSpacer::setFixedSize(const BSize& fixedSize)
{
	if (member.fixedSize != fixedSize)
	{
		member.fixedSize = fixedSize;
		if (member.layout)
			member.layout->dirty();
	}
}
BSize BSpacer::fixedSize() const
{
	return member.fixedSize;
}

void BSpacer::setMinWidth(int minWidth)
{
	setMinSize(minWidth, member.minSize.height());
}
int BSpacer::minWidth() const
{
	return member.minSize.width();
}

void BSpacer::setMinHeight(int minHeight)
{
	setMinSize(member.minSize.width(), minHeight);
}
int BSpacer::minHeight() const
{
	return member.minSize.height();
}

void BSpacer::setMinSize(int minWidth, int minHeight)
{
	setMinSize(BSize(minWidth, minHeight));
}
void BSpacer::setMinSize(const BSize& minSize)
{
	if (member.minSize != minSize)
	{
		member.minSize = minSize;
		if (member.layout)
			member.layout->dirty();
	}
}
const BSize& BSpacer::minSize() const
{
	return member.minSize;
}

void BSpacer::setMaxWidth(int maxWidth)
{
	setMaxSize(maxWidth, member.maxSize.height());
}
int BSpacer::maxWidth() const
{
	return member.maxSize.width();
}

void BSpacer::setMaxHeight(int maxHeight)
{
	setMaxSize(member.maxSize.width(), maxHeight);
}
int BSpacer::maxHeight() const
{
	return member.maxSize.height();
}

void BSpacer::setMaxSize(int maxWidth, int maxHeight)
{
	setMaxSize(BSize(maxWidth, maxHeight));
}
void BSpacer::setMaxSize(const BSize& maxSize)
{
	if (member.maxSize != maxSize)
	{
		member.maxSize = maxSize;
		if (member.layout)
			member.layout->dirty();
	}
}
const BSize& BSpacer::maxSize() const
{
	return member.maxSize;
}

void BSpacer::setSizePolicy(Policy widthPolicy, Policy heightPolicy)
{
	setSizePolicy(BSizePolicy(widthPolicy, heightPolicy));
}
void BSpacer::setSizePolicy(const BSizePolicy& sizePolicy)
{
	if (member.sizePolicy != sizePolicy)
	{
		member.sizePolicy = sizePolicy;
		if (member.layout)
			member.layout->dirty();
	}
}
const BSizePolicy& BSpacer::sizePolicy() const
{
	return member.sizePolicy;
}
